/******************************************************************************

  File Name     : hinnie_session.h
  Version       : Initial Draft
  Author        : tongzhilin
  Created       : 2020/8/6
  Last Modified :
  Description   : hinnie_session
  Function List :
  History       :
  1.Date        : 2020/8/6
    Author      : tongzhilin
    Modification: Created file

******************************************************************************/
#pragma once
#include "mp_common.h"
#include "mpi_nnie.h"
#include "hinnie_model.h"

typedef enum
{
    HINNIE_SESSION_NNIE_ID_0        = 0x0,
    HINNIE_SESSION_NNIE_ID_1        = 0x1,
    HINNIE_SESSION_NNIE_AUTO        = 0x2,

    HINNIE_SESSION_NNIE_BUTT
}HINN_SESSION_NNIE_ID_E;

class HinnieSession
{
  public:
    HinnieSession(HinnieModel* _pModel, INT32 _s32MaxBatch = 1, bool _bTest = false);
    virtual ~HinnieSession();

    void set_input_blob(INT32 _no, const SVP_BLOB_S& _stSvpBlob, bool _bFlush=true);
    void set_output_blob(INT32 _no, const SVP_BLOB_S& _stSvpBlob);
    void set_nnie_id(HINN_SESSION_NNIE_ID_E _eNnieId);

    void execute(bool _bBlock = true);
    void sync();

private:
    static UINT64         m_u64TotalQueryTime_Nnie0;
    static UINT64         m_u64TotalQueryTime_Nnie1;
    static std::mutex     m_mtNnieQueue;

private:
    SVP_NNIE_ID_E get_nnie_id();

    HinnieModel*            m_pModel;
    std::vector<SVP_BLOB_S> m_stvInputSvpBlob;
    std::vector<SVP_BLOB_S> m_stvOutputSvpBlob;
    HINN_SESSION_NNIE_ID_E  m_eSessionNnieId;
    SVP_NNIE_ID_E           m_eNnieId_Use;

    SVP_MEM_INFO_S          m_pTmpBuf;
    SVP_MEM_INFO_S          m_pTaskBuf;

    SVP_NNIE_HANDLE         m_pNnieHdl;
    SVP_NNIE_FORWARD_CTRL_S m_stSvpCtrl;

    //query time vector,frome model
    std::vector<UINT64>     m_u64vQueryTime;
    //session excute time one time
    UINT64                  m_u64CurQueryTime = 0;
    //nnie block
    bool                    m_bNnieQueryBlock = true;
    //session test
    bool                    m_bTest;

    INT32                   m_s32CurBatch = 1;
    INT32                   m_s32MaxBatch;
};

